package com.srcbox.file.fragment.pager

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.widget.SwitchCompat
import androidx.fragment.app.Fragment
import com.srcbox.file.R
import com.srcbox.file.ui.About
import com.srcbox.file.ui.Select
import com.srcbox.file.data.AppSetting
import com.srcbox.file.util.EggUtil

class MainC() : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val v = inflater.inflate(R.layout.main_nav_three, container, false)
        initView(v)
        return v
    }

    private fun initView(v: View) {
        val threeImg1 = v.findViewById<TextView>(R.id.icon_three_img1)
        val threeImg2 = v.findViewById<TextView>(R.id.icon_three_img2)
        val threeImg3 = v.findViewById<TextView>(R.id.icon_three_img3)
        val threeImg4 = v.findViewById<TextView>(R.id.icon_three_img4)
        val threeImg5 = v.findViewById<TextView>(R.id.icon_three_img5)
        val threeImg6 = v.findViewById<TextView>(R.id.icon_three_img6)
        val threeImg7 = v.findViewById<TextView>(R.id.icon_three_img7)

        val switchBtn = v.findViewById<SwitchCompat>(R.id.cancelSwitchOn)
        val osAppSwitchBtn = v.findViewById<SwitchCompat>(R.id.osAppSwitchOn)
        val goCoder = v.findViewById<LinearLayout>(R.id.go_coder)
        val goQun = v.findViewById<LinearLayout>(R.id.goQun)
        val selectFile = v.findViewById<LinearLayout>(R.id.select_file)
        EggUtil.setSwitchColor(switchBtn)
        EggUtil.setSwitchColor(osAppSwitchBtn)
        EggUtil.loadIcon(context as Activity, threeImg1, "#cccccc")
        EggUtil.loadIcon(context as Activity, threeImg2, "#cccccc")
        EggUtil.loadIcon(context as Activity, threeImg3, AppSetting.FONT_COLOR)
        EggUtil.loadIcon(context as Activity, threeImg4, AppSetting.FONT_COLOR)
        EggUtil.loadIcon(context as Activity, threeImg5, AppSetting.FONT_COLOR)
        EggUtil.loadIcon(context as Activity, threeImg6, AppSetting.FONT_COLOR)
        EggUtil.loadIcon(context as Activity, threeImg7, AppSetting.FONT_COLOR)

        val jsonO = EggUtil.readSetting(context!!)
        println(jsonO.toJSONString())
        switchBtn.isChecked = jsonO.getBoolean("g_is_cancel")
        osAppSwitchBtn.isChecked = jsonO.getBoolean("os_is_cancel")
        goCoder.setOnClickListener {
            startActivity(Intent(context, About::class.java))
        }

        selectFile.setOnClickListener {
            startActivity(Intent(context, Select::class.java))
        }

        goQun.setOnClickListener {
            EggUtil.joinQQGroup(context!!, AppSetting.QUN_KEY)
        }

        switchBtn.setOnClickListener {
            EggUtil.writeSetting(context!!, "g_is_cancel", (switchBtn.isChecked).toString())
//            switchBtn.isChecked = switchBtn.isChecked
        }

        osAppSwitchBtn.setOnClickListener {
            EggUtil.writeSetting(context!!, "os_is_cancel", (osAppSwitchBtn.isChecked).toString())
        }
    }
}